import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:ball_lion/utils/utils.dart';
import 'package:ball_lion/widgets/card.dart';
import 'package:ball_lion/widgets/loading/shimmer_loading_widget.dart';

class LoadingMatchList extends StatelessWidget {
  const LoadingMatchList({super.key, required this.sportsId})
      : isSliver = false;
  const LoadingMatchList.sliver({
    super.key,
    required this.sportsId,
  }) : isSliver = true;

  final bool isSliver;
  final int sportsId;

  @override
  Widget build(BuildContext context) {
    if (isSliver) {
      return SliverList(
          delegate: SliverChildListDelegate(List.generate(
              10, (index) => sportsId == 1 ? _soccerItem() : _basketItem())));
    } else {
      return SingleChildScrollView(
        child: Column(
          children: List.generate(
              10, (index) => sportsId == 1 ? _soccerItem() : _basketItem()),
        ),
      );
    }
  }

  Widget _soccerItem() {
    return Block(
      cardStyle: const CardStyle(
        margin: EdgeInsets.fromLTRB(8, 8, 8, 0),
        padding: EdgeInsets.symmetric(horizontal: 16, vertical: 12),
      ),
      child: Column(
        children: [
          _buildLoadingHead(),
          const SizedBox(height: 14),
          _buildLoadingBody(),
          const SizedBox(height: 16),
          _buildLoadingBottom()
        ],
      ),
    );
  }

  Widget _buildLoadingHead() {
    return const Row(
      mainAxisAlignment: MainAxisAlignment.spaceBetween,
      children: [
        ShimmerLoading(width: 16 * 5, height: 16),
        ShimmerLoading(width: 16 * 1, height: 16),
        ShimmerLoading(width: 16 * 5, height: 16),
      ],
    );
  }

  Widget _buildLoadingBody() {
    return const Row(
      mainAxisAlignment: MainAxisAlignment.spaceEvenly,
      children: [
        ShimmerLoading(width: 21, height: 21),
        ShimmerLoading(width: 21 * 3, height: 21),
        ShimmerLoading(width: 21, height: 21, shape: BoxShape.circle),
        ShimmerLoading(width: 20, height: 29, radius: 4),
        ShimmerLoading(width: 20, height: 29, radius: 4),
        ShimmerLoading(width: 21, height: 21, shape: BoxShape.circle),
        ShimmerLoading(width: 21 * 3, height: 21),
        ShimmerLoading(width: 21, height: 21)
      ],
    );
  }

  Widget _buildLoadingBottom() {
    return const Row(
      mainAxisAlignment: MainAxisAlignment.center,
      children: [ShimmerLoading(width: 16 * 8, height: 16)],
    );
  }

  Widget _basketItem() {
    return Block(
      cardStyle: const CardStyle(
        margin: EdgeInsets.fromLTRB(8, 8, 8, 0),
        padding: EdgeInsets.all(8),
      ),
      child: Column(
        children: [
          const Row(
            children: [
              ShimmerLoading(width: 105, height: 17, radius: 2),
              Spacer(),
              ShimmerLoading(width: 46, height: 17, radius: 2),
            ],
          ),
          const SizedBox(height: 8),
          Row(
            children: [
              const ShimmerLoading(width: 16, height: 16, radius: 2),
              Container(width: 8),
              Expanded(
                child: Column(
                    children: List<Widget>.generate(
                        2,
                        (index) => Row(
                              children: [
                                const ShimmerLoading(
                                    width: 16, height: 16, radius: 2),
                                Container(width: 5),
                                const ShimmerLoading(
                                    width: 87, height: 18, radius: 2),
                                const Spacer(),
                                const ShimmerLoading(
                                    width: 146, height: 18, radius: 2)
                              ],
                            )).insertEvery(Container(height: 8))),
              )
            ],
          )
        ],
      ),
    );
  }
}
